<template>
  <div class="dashboard-editor-container">
    <panel-group :data="data" @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="data[type].weeks ? data[type].weeks : {}" />
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="24">
        <div class="chart-wrapper">
          <bar-chart :chart-data="data[type].months ? data[type].months : {}" />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import { getStatisics } from '@/api/statistics'

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      date: new Date(),
      data: {
        member: {
          total: 0,
          weeks: [],
          months: []
        },
        order: {
          total: 0,
          weeks: [],
          months: []
        },
        reserve: {
          total: 0,
          weeks: [],
          months: []
        },
        amount: {
          total: 0,
          weeks: [],
          months: []
        },
      },
      type: 'member'
    }
  },
  created() {
    this.getStatisics()
  },
  methods: {
    handleSetLineChartData(type) {
      this.type = type
    },
    getStatisics() {
      getStatisics(this.date.getFullYear()).then(res => {
        this.data = res.data
      })
    }
  },

}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
